package serwer.prezentacja;

import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import java.io.IOException;
import serwer.dane.ObslugaBazyDanychKont;
import serwer.logika.LogikaKont;

public class SluchajUzytkownik {
    private LogikaKont lk;

    SluchajUzytkownik(ObslugaBazyDanychKont obdk) {
        lk = new LogikaKont(obdk);
    }

    public void sluchaj(int port) throws IOException {
        Server server = new Server();
        network.ClassRegister.register(server);
        
        System.out.println("Server> running on port " + port);
        
        server.addListener(new Listener() {
            public void connected(Connection connection) {
                System.out.println("Server> new connection " + connection.getRemoteAddressTCP());
            }

            public void disconnected(Connection connection) {
                System.out.println("Server> connection ends " + connection.getRemoteAddressTCP());
            }

            public void received(Connection connection, Object object) {
                System.out.println("Server> received something");
                if (object instanceof network.data.request.DolaczenieSieDoGry) {
                } else if (object instanceof network.data.request.GotowyNaStart) {
                    network.data.request.GotowyNaStart res = (network.data.request.GotowyNaStart) object;
                    System.out.println("Server> got request 'gotowynastart' +mes = ");
                } else if (object instanceof network.data.request.ListaPokojow) {
                } else if (object instanceof network.data.request.OdnowienieHasla) {
                } else if (object instanceof network.data.request.Ranking) {
                } else if (object instanceof network.data.request.Rejestrowanie) {
                } else if (object instanceof network.data.request.StartowanieGry) {
                } else if (object instanceof network.data.request.StatusPokoju) {
                } else if (object instanceof network.data.request.TworzenieNowejGry) {
                } else if (object instanceof network.data.request.WysylanieWiadomosci) {
                } else if (object instanceof network.data.request.Zalogowanie) {
                    network.data.request.Zalogowanie res = (network.data.request.Zalogowanie) object;
                    System.out.println("Server> got request 'Zalogowanie'");
                } else if (object instanceof network.data.request.ZmianaSlotu) {
                } else if (object instanceof network.data.request.ZmuszenieStartu) {
                } else if (object instanceof network.data.request.StatystykaGracza) {
                    network.data.request.StatystykaGracza res = (network.data.request.StatystykaGracza) object;

                }

            }
        });
        server.bind(port);
        server.start();
    }

}
